/*
 * @Author: zhang gen yuan
 * @Date: 2021-10-18 09:18:38
 * @Descripttion: 
 */
/*
 * @Author: zhang gen yuan
 * @Date: 2021-10-18 09:18:38
 * @Descripttion: 
 */
import { Controller, Get, Query } from '@nestjs/common'
import { UserService } from './user.service'
import { User } from '../entities/user.entity'

@Controller('user')
export class UserController {
    constructor(private readonly userSrvice: UserService) {}

    @Get()
    root(): string{
        return this.userSrvice.root()
    }

    @Get('save')
    save(@Query() query): any{
        console.log(query)
        let user = new User()
        user.name = query.name
        user.age = Number(query.age)
        if(query.id){
            user.id = Number(query.id)
        }
        return this.userSrvice.save(user)
    }

    @Get('get')
    get(@Query() query): any{
        if(query.id){
            query.id = Number(query.id)
        }
        if(query.age){
            query.age = Number(query.age)
        }
        return this.userSrvice.get(query)
    }
    
    @Get('remove')
    remove(@Query() query): any{

        if(query.id){
            query.id = Number(query.id)
        }
        if(query.age){
            query.age = Number(query.age)
        }
        return this.userSrvice.remove(query)
    }
}